package serv

import (
	"fmt"

	"github.com/gin-gonic/gin"
)

func AdminBaseGetRoleMenusCtrl(c *gin.Context) {
	if c.Request.Method == "POST" {
		var adminNodeArr []map[string]any
		where := "pid=0"

		dbEngine.Table("f_node").Select("id, title, path as access").Where(where).OrderBy("sort asc").Find(&adminNodeArr)

		for index, v := range adminNodeArr {
			var tmpArr []map[string]any
			dbEngine.Table("f_node").Select("id, title, path as access").Where("pid=?", v["id"]).OrderBy("sort asc").Find(&tmpArr)
			if len(tmpArr) > 0 {
				adminNodeArr[index]["children"] = tmpArr
			} else {
				adminNodeArr[index]["children"] = nil
			}
			fmt.Println(index, v)
		}

		c.JSON(200, map[string]any{
			"status": 200,
			"menus":  adminNodeArr,
		})
	} else {
	}
}
